<?php

namespace app\http\middleware;

use app\api\service\ApiResponse;
use app\api\service\StatusCode;
use app\api\service\UserToken;

class Token
{
    public function handle($request, \Closure $next)
    {
        //跳过
        if($request->action() !== 'create'){
            $get = $request->header();
            //检查有没有访问token
            UserToken::checkAccessMustHasToken();
            //验证token
            if(UserToken::checkAccessToken($get['token']) == false){
                return ApiResponse::error(StatusCode::SERVER_ERROR,'token验证失败');
            }
        }          
        return $next($request);
    }
}
